﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace jobsheetFinal
{
    public partial class frmLogIn : Form
    {
        public frmLogIn()
        {
            InitializeComponent();
        }

        private void gbxLogIn_Enter(object sender, EventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string userName = tbxUserName.Text;
            string password = tbxPassword.Text;
            string position = Convert.ToString(comboPosition.SelectedItem);

            if (position == "Admin")
            {
                bool Result = DBManager.LoginValidateRegisterAdmin(userName, password);

                if (Result == true)
                {
                    this.Hide();
                    AllFormClass.Admin.Show();
                }
                else
                {
                    tbxPassword.Clear();
                    tbxUserName.Clear();
                    lblError.Visible = true;
                    lblError.Text="Wrong User Name and Password.Try Again";
                }
            }
            else if (position == "Salesman")
            {
                bool Result = DBManager.LoginValidateRegisterSales(userName, password);
                if (Result == true)
                {
                    this.Hide();
                    AllFormClass.SalesMainPage.Show();
                }
                else
                {

                    tbxPassword.Clear();
                    tbxUserName.Clear();
                    lblError.Visible = true;
                    lblError.Text = "Wrong User Name and Password.Try Again";
                }

            }
            else
            {
                lblError.Visible=true;
                lblError.Text = "Please choose the correct position.";
            }
        }


        private void frmLogIn_Load(object sender, EventArgs e)
        {
             
        }

        private void bthExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void LinkLabelRequestNewPassword_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Hide();
            AllFormClass.ReqNewPassword.Show();
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Hide();
            AllFormClass.UserManage.Show();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Hide();
            AllFormClass.RegisterNewUser.Show();
        }
    }
}
